<template>
  <div style="display: flex;line-height: 68px">
    <div>
      <i class="el-icon-s-fold" style="font-size: 20px" @click="collapse"></i>
    </div>
    <div style="flex:1;text-align: center;font-size: 34px">
      <span>欢迎来到仓库系统</span>
    </div>
    <el-dropdown>
      <span>{{ user.name }}<i class="el-icon-arrow-down" style="margin-left: 5px"></i></span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
        <el-dropdown-item @click.native="loginOut">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>

  </div>
</template>

<script>
export default {
  name: "AppHeader",
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem('CurUser'))
    }
  },
  methods: {
    toUser() {
      this.$router.push("/AppHome")
    },
    loginOut() {
      this.$confirm('确定退出吗','提示',{
        confirmButtonText:'确定',
        type:'warning',
        center:true,
      }).then(()=>{
        this.$router.push("/")
        sessionStorage.clear()
        this.$message({
          message:'退出成功',
          center:true,
          type:'success',
          duration:1000
        })
      })
          .catch(()=>{
            this.$message({
              message: '已取消',
              center: true,
              duration:1000
            });
          })
    },
    collapse() {
      this.$emit('doCollapse')
    }
  },
  created(){
    this.$router.push("/AppHome")
  }
}
</script>

<style scoped>

</style>
